$term = $_GET['q'] ?? '';
$suggestions = [];

if (strlen($term) > 2) {

$stmt = $pdo->prepare("
SELECT name_zh, 'ship' AS type FROM ships
WHERE name_zh LIKE ? LIMIT 5
UNION ALL
SELECT name_zh, 'port' AS type FROM ports
WHERE name_zh LIKE ? LIMIT 5
");
$stmt->execute(["%$term%", "%$term%"]);
$suggestions = $stmt->fetchAll();
}

header('Content-Type: application/json');
echo json_encode($suggestions);